#include <stdio.h>
#include <stdlib.h>

#define Min(a,b) (a) < (b) ? (a) : (b)

typedef struct {
    char* data;
    int length;
} MyStr;

int MyStrlen(MyStr s) {
    return s.length;
}

int MyStrcmp(MyStr s1, MyStr s2) {
    int n = Min(s1.length, s2.length);
    for (int i = 0; i < n; i++) {
        if (s1.data[i] != s2.data[i]) {
            return s1.data[i] - s2.data[i];
        }
    }
    return s1.length - s2.length;
}

int MyStrncmp(MyStr s1, MyStr s2, int n) {
    int len = Min(Min(s1.length, s2.length), n);
    for (int i = 0; i < len; i++) {
        if (s1.data[i] != s2.data[i]) {
            return s1.data[i] - s2.data[i];
        }
    }
    return 0;
}


void MyStrcpy(MyStr* dest, MyStr src) {
    for (int i = 0; i < src.length; i++) {
        dest->data[i] = src.data[i];
    }
    dest->length = src.length;
}

void MyStrncpy(MyStr* dest, MyStr src, int n) {
    int len = Min(src.length, n);
    for (int i = 0; i < len; i++) {
        dest->data[i] = src.data[i];
    }
    dest->length = len;
}

void MyStrcat(MyStr* dest, MyStr src) {
    for (int i = 0; i < src.length; i++) {
        dest->data[dest->length + i] = src.data[i];
    }
    dest->length += src.length;
}

void MyStrncat(MyStr* dest, MyStr src, int n) {
    int len = Min(src.length, n);
    for (int i = 0; i < len; i++) {
        dest->data[dest->length + i] = src.data[i];
    }
    dest->length += len;
}

const char* MyStrstr(MyStr dest, MyStr src) {
    for (int i = 0; i <= dest.length - src.length; i++) {
        if (MyStrncmp(dest, src, src.length) == 0) {
            return dest.data + i;
        }
    }
    return NULL;
}

